<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>航线统计查询</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%@ include file="/pages/common/header.jsp"%>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/datePicker/WdatePicker.js"></script>
<script type="text/javascript">
var localchannel = "<s:property value="#parameters['channel']"/>";
var localtype = "<s:property value="#parameters['type']"/>";
var localdate = "<s:property value="#parameters['date']"/>";
var gridManager;
var _dialog;
$(function (){
	
	var selectUrl="<%=contextPath %>/preprocess-PlaneInfo-listSourceSel.action";
	$.ajax({
			url: selectUrl,
			type: 'POST',
			dataType: 'json',
			error: function(){
				alert('渠道列表请求出错');
			},
			success: function(data){
				$('#channel_ID').html('');
				$('#channel_ID').append('<option value="">请选择渠道</option>' );
				$.each(data.listSource, function(idx, e){
					$('#channel_ID').append('<option value='+e.hbaseKey+'>'+e.shortName+'</option>' );
				});
				$('#channel_ID').find("option[value='"+localchannel+"']").attr("selected","selected");
				$('#type_ID').find("option[value='"+localtype+"']").attr("selected","selected");
				$('#date_ID').val(localdate);
				gridManager = PageLoader.initGridPanel();
			}

		});
	
});

PageLoader = {

 initGridPanel:function(){
	 var g = $("#maingrid").ligerGrid({
       //  checkbox:true,
         height : '100%',
         rowHeight: 28,//行默认的高度
         headerRowHeight: 30,//表头行的高度
         pageSize : 20,
         onToNext:next,//条件查询方法
         columns: [
                   { display: '渠道', name: 'channel', width : 160, editor: { type: 'text' }}, 
                   { display: '渠道名称', name: 'channelName', width : 160, editor: { type: 'text' }},
                   { display: '抓取时间', name: 'grabDate',width : 150,editor: { type: 'text' }},
                   { display: '出发城市', name:'fromCity',editor:{type:'text'}},
                   { display: '到达城市', name:'toCity',editor:{type:'text'}},
                   { display: '航班数', name:'flightSize',editor:{type:'text'},render: function (rowdata, rowindex, value)
                       {
                 	  var param = '"' + rowdata.grabDate + '"';
                       var h = "<a href='javascript:clickFlightSize(" + param + ",\""+rowdata.channel+"\",\""+
                       rowdata.fromCity+"\",\""+rowdata.toCity+"\")'>"
                       +rowdata.flightSize+"</a> ";
                       return h;
                   }},
                  
                 ], 
           enabledEdit: false, clickToEdit: false, 
           parms : [
						 {name:"type",value: $("#type_ID").val()},
						 {name:"channel",value: $("#channel_ID").val()},
						 {name:"date",value: $("#date_ID").val()},
						 {name:"fromCity",value: $("#fromCity_ID").val()},
			         	 {name:"toCity",value: $("#toCity_ID").val()},
						 {name:"method",value: "airLine"},
                          ],
           url:"<%=contextPath %>/preprocess-AirLineCount-pageJson.action",
           width: '100%',
    });
	 g.toggleCol("id",false);//隐藏id列
	 return g;
 }
}


//查询方法
function searchAction(){
	
	var channel=$("#channel_ID").val();
	var grabdate=$("#date_ID").val();
	if((null==channel || ""==channel ) && (null==grabdate || ""==grabdate)){
		alert("渠道和日期请选择其中一个");
		return;
	}
     //form validate
   if(!Validator.Validate(document.getElementById("searchForm"),3))return;
//	var param=$("#searchForm").serialize();
	g = $("#maingrid").ligerGrid({
      //  checkbox:true,
        height : '100%',
        rowHeight: 28,//行默认的高度
        headerRowHeight: 30,//表头行的高度
        pageSize : 20,
        onToNext:next,//条件查询方法
        newPage:'1',
        columns: [
                  { display: '渠道', name: 'channel', width : 160, editor: { type: 'text' }}, 
                  { display: '渠道名称', name: 'channelName', width : 160, editor: { type: 'text' }},
                  { display: '抓取时间', name: 'grabDate',width : 150,editor: { type: 'text' }},
                  { display: '出发城市', name:'fromCity',editor:{type:'text'}},
                  { display: '到达城市', name:'toCity',editor:{type:'text'}},
                  { display: '航班数', name:'flightSize',editor:{type:'text'},render: function (rowdata, rowindex, value)
                       {
                 	  var param = '"' + rowdata.grabDate + '"';
                       var h = "<a href='javascript:clickFlightSize(" + param + ",\""+rowdata.channel+"\",\""+
                       rowdata.fromCity+"\",\""+rowdata.toCity+"\")'>"
                       +rowdata.flightSize+"</a> ";
                       return h;
                   }},
                ], 
          enabledEdit: false, clickToEdit: false, 
          parms : [
						 {name:"type",value: $("#type_ID").val()},
						 {name:"channel",value: $("#channel_ID").val()},
						 {name:"date",value: $("#date_ID").val()},
						 {name:"fromCity",value: $("#fromCity_ID").val()},
			         	 {name:"toCity",value: $("#toCity_ID").val()},
						 {name:"method",value: "airLine"},
                         ],
          url:"<%=contextPath %>/preprocess-AirLineCount-pageJson.action",
       width: '100%',

   });
	//gridManager.loadServerData(param);/*执行服务器查询*/
}

/*分页条件查询参数*/
function next(){
	
	gridManager.setOptions({
        parms: [
				{name:"type",value: $("#type_ID").val()},
                {name:"channel",value: $("#channel_ID").val()},
         	    {name:"date",value: $("#date_ID").val()},
         	    {name:"fromCity",value: $("#fromCity_ID").val()},
        	    {name:"toCity",value: $("#toCity_ID").val()},
         	    {name:"method",value: "airLine"}
        ]
    });
}

function clickFlightSize(date,channel,fromCity,toCity){
	top.f_addTab(null, 'Hbase查询',
			"preprocess-PlaneInfo-list.action?channel=" + channel+"&type="+$("#type_ID").val()+
					"&date="+date+"&fromCity="+fromCity+"&toCity="+toCity);
}
</script>
</head>
<body>
<div style="width:98%;height:100%;padding-left: 5px;">
<br>
<br>
<div class="searchtitle" >
	<!-- search form -->
	<form name="searchForm" id="searchForm" target="_self">
	<table border="0" cellspacing="0" cellpadding="0" class="form2column">
	  <tr>
		  <td class="label">类型:</td>
		  <td> 
		 	<select name="type"  id="type_ID" class="select-common">
				<option value="single">单程</option>
				<option value="double">往返</option>
			</select>
		   </td>
		  
		  <td class="label"> 渠道:</td>
		  <td >
		    <select name="channel"  id="channel_ID" class="select-common">
				<option value="">请选择</option>
			</select> 
		  </td>
		  <td class="label">抓取日期：</td>
		  <td  style="width:250px;">
				<input name="date" type="text"	id="date_ID" style="width: 180px"    
					onClick="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'2013-03-01',maxDate:'%y-%M-{%d-1}'})" readonly="readonly"/>
		  </td>

	 </tr>
	 
	 <tr>
		<td class="label">出发城市：</td>
	 	<td> <input name="fromCity" type="text" id="fromCity_ID" /> </td>
	 	
	 	<td class="label">到达城市：</td>
	 	<td> <input name="toCity" type="text" id="toCity_ID" /> </td>
	 	
	 	 <td colspan="2" style="text-align: center;"><input id="searchButton" type="button" class="btn-normal" onclick="searchAction()" value="查询" /></td>
	 </tr>
	</table>	
	</form>
</div>
<!-- grid -->
<div id="maingrid"></div> 
</div>
</body>
</html>
